﻿using Abp.Application.Services.Dto;
using Abp.AspNetCore.Mvc.Controllers;
using Batman.RefiningPharmacist.Services;
using Batman.RefiningPharmacist.Services.Filters;
using Batman.RefiningPharmacist.Services.Inputs;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace Batman.RefiningPharmacist.Controllers
{
    public class CompositeController : AbpController
    {
        public CompositeManager CompositeManager { get; set; }

        public CompositeReader CompositeReader { get; set; }



        /// <summary>
        /// 新建合成物接口 
        /// API:/Composite/Create
        /// </summary>
        /// <param name="model"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public IActionResult Create(CreateCompositeInput model, string userId)
        {
            if (model.CompositeItems == null)
            {
                model.CompositeItems = new List<CreateCompositeItemInput>();
            }
            var result = CompositeManager.Create(model, userId);
            return Json(model);
        }

        /// <summary>
        /// 获取 Composite
        /// API:/Composite/Get
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public IActionResult Get(CompositeFilter filter, PagedResultRequestDto page)
        {
            var result = CompositeReader.Get(filter, page);

            return Json(result);
        }

        /// <summary>
        /// 获取compositeItem(购物单项)
        /// </summary>
        /// <param name="compositeId"></param>
        /// <returns></returns>
        public IActionResult Items(CompositeItemFilter filter)
        {
            var result = CompositeReader.GetCompositeItems(filter);

            return Json(result);
        }

        /// <summary>
        /// 批量删除代办集合
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public IActionResult Destroy(List<int> ids)
        {
            CompositeManager.Destroy(ids);

            return Json(new { });
        }
    }
}
